package com.fan.leetcode;

/**
 * 1221. 分割平衡字符串
 * @author ZhangFan
 * @since 2021/9/7 下午 8:52
 */
public class Question1221 {
    public int balancedStringSplit(String s) {
        int balance = 0;
        int count = 0;
        for (char c : s.toCharArray()) {
            if (c == 'L') {
                balance++;
            } else if (c == 'R') {
                balance--;
            }
            if (balance == 0) {
                count++;
            }
        }
        return count;
    }
}
